package com.google.android.gcm;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.os.Build.VERSION;
import android.util.Log;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public final class GCMRegistrar
{
  private static final String BACKOFF_MS = "backoff_ms";
  private static final int DEFAULT_BACKOFF_MS = 3000;
  private static final String GSF_PACKAGE = "com.google.android.gsf";
  private static final String PREFERENCES = "com.google.android.gcm";
  private static final String PROPERTY_APP_VERSION = "appVersion";
  private static final String PROPERTY_ON_SERVER = "onServer";
  private static final String PROPERTY_REG_ID = "regId";
  private static final String TAG = "GCMRegistrar";
  private static GCMBroadcastReceiver sRetryReceiver;

  private GCMRegistrar()
  {
    throw new UnsupportedOperationException();
  }

  public static void checkDevice(Context paramContext)
  {
    int i = Build.VERSION.SDK_INT;
    if (i < 8)
      throw new UnsupportedOperationException("Device must be at least API Level 8 (instead of " + i + ")");
    PackageManager localPackageManager = paramContext.getPackageManager();
    try
    {
      localPackageManager.getPackageInfo("com.google.android.gsf", 0);
      return;
    }
    catch (PackageManager.NameNotFoundException localNameNotFoundException)
    {
    }
    throw new UnsupportedOperationException("Device does not have package com.google.android.gsf");
  }

  // ERROR //
  public static void checkManifest(Context paramContext)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 74	android/content/Context:getPackageManager	()Landroid/content/pm/PackageManager;
    //   4: astore_1
    //   5: aload_0
    //   6: invokevirtual 86	android/content/Context:getPackageName	()Ljava/lang/String;
    //   9: astore_2
    //   10: new 49	java/lang/StringBuilder
    //   13: dup
    //   14: aload_2
    //   15: invokestatic 92	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   18: invokespecial 54	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   21: ldc 94
    //   23: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   26: invokevirtual 67	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   29: astore_3
    //   30: aload_1
    //   31: aload_3
    //   32: sipush 4096
    //   35: invokevirtual 98	android/content/pm/PackageManager:getPermissionInfo	(Ljava/lang/String;I)Landroid/content/pm/PermissionInfo;
    //   38: pop
    //   39: aload_1
    //   40: aload_2
    //   41: iconst_2
    //   42: invokevirtual 80	android/content/pm/PackageManager:getPackageInfo	(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;
    //   45: astore 7
    //   47: aload 7
    //   49: getfield 104	android/content/pm/PackageInfo:receivers	[Landroid/content/pm/ActivityInfo;
    //   52: astore 8
    //   54: aload 8
    //   56: ifnull +9 -> 65
    //   59: aload 8
    //   61: arraylength
    //   62: ifne +79 -> 141
    //   65: new 106	java/lang/IllegalStateException
    //   68: dup
    //   69: new 49	java/lang/StringBuilder
    //   72: dup
    //   73: ldc 108
    //   75: invokespecial 54	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   78: aload_2
    //   79: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   82: invokevirtual 67	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   85: invokespecial 109	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   88: athrow
    //   89: astore 4
    //   91: new 106	java/lang/IllegalStateException
    //   94: dup
    //   95: new 49	java/lang/StringBuilder
    //   98: dup
    //   99: ldc 111
    //   101: invokespecial 54	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   104: aload_3
    //   105: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   108: invokevirtual 67	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   111: invokespecial 109	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   114: athrow
    //   115: astore 6
    //   117: new 106	java/lang/IllegalStateException
    //   120: dup
    //   121: new 49	java/lang/StringBuilder
    //   124: dup
    //   125: ldc 113
    //   127: invokespecial 54	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   130: aload_2
    //   131: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   134: invokevirtual 67	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   137: invokespecial 109	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   140: athrow
    //   141: ldc 29
    //   143: iconst_2
    //   144: invokestatic 119	android/util/Log:isLoggable	(Ljava/lang/String;I)Z
    //   147: ifeq +36 -> 183
    //   150: ldc 29
    //   152: new 49	java/lang/StringBuilder
    //   155: dup
    //   156: ldc 121
    //   158: invokespecial 54	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   161: aload_2
    //   162: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   165: ldc 123
    //   167: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   170: aload 8
    //   172: arraylength
    //   173: invokevirtual 58	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
    //   176: invokevirtual 67	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   179: invokestatic 127	android/util/Log:v	(Ljava/lang/String;Ljava/lang/String;)I
    //   182: pop
    //   183: new 129	java/util/HashSet
    //   186: dup
    //   187: invokespecial 130	java/util/HashSet:<init>	()V
    //   190: astore 9
    //   192: aload 8
    //   194: arraylength
    //   195: istore 10
    //   197: iconst_0
    //   198: istore 11
    //   200: iload 11
    //   202: iload 10
    //   204: if_icmplt +23 -> 227
    //   207: aload 9
    //   209: invokeinterface 136 1 0
    //   214: ifeq +52 -> 266
    //   217: new 106	java/lang/IllegalStateException
    //   220: dup
    //   221: ldc 138
    //   223: invokespecial 109	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   226: athrow
    //   227: aload 8
    //   229: iload 11
    //   231: aaload
    //   232: astore 12
    //   234: ldc 140
    //   236: aload 12
    //   238: getfield 145	android/content/pm/ActivityInfo:permission	Ljava/lang/String;
    //   241: invokevirtual 149	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   244: ifeq +16 -> 260
    //   247: aload 9
    //   249: aload 12
    //   251: getfield 152	android/content/pm/ActivityInfo:name	Ljava/lang/String;
    //   254: invokeinterface 155 2 0
    //   259: pop
    //   260: iinc 11 1
    //   263: goto -63 -> 200
    //   266: aload_0
    //   267: aload 9
    //   269: ldc 157
    //   271: invokestatic 161	com/google/android/gcm/GCMRegistrar:checkReceiver	(Landroid/content/Context;Ljava/util/Set;Ljava/lang/String;)V
    //   274: aload_0
    //   275: aload 9
    //   277: ldc 163
    //   279: invokestatic 161	com/google/android/gcm/GCMRegistrar:checkReceiver	(Landroid/content/Context;Ljava/util/Set;Ljava/lang/String;)V
    //   282: return
    //
    // Exception table:
    //   from	to	target	type
    //   30	39	89	android/content/pm/PackageManager$NameNotFoundException
    //   39	47	115	android/content/pm/PackageManager$NameNotFoundException
  }

  private static void checkReceiver(Context paramContext, Set<String> paramSet, String paramString)
  {
    PackageManager localPackageManager = paramContext.getPackageManager();
    String str1 = paramContext.getPackageName();
    Intent localIntent = new Intent(paramString);
    localIntent.setPackage(str1);
    List localList = localPackageManager.queryBroadcastReceivers(localIntent, 32);
    if (localList.isEmpty())
      throw new IllegalStateException("No receivers for action " + paramString);
    if (Log.isLoggable("GCMRegistrar", 2))
      Log.v("GCMRegistrar", "Found " + localList.size() + " receivers for action " + paramString);
    Iterator localIterator = localList.iterator();
    String str2;
    do
    {
      if (!localIterator.hasNext())
        return;
      str2 = ((ResolveInfo)localIterator.next()).activityInfo.name;
    }
    while (paramSet.contains(str2));
    throw new IllegalStateException("Receiver " + str2 + " is not set with permission " + "com.google.android.c2dm.permission.SEND");
  }

  static String clearRegistrationId(Context paramContext)
  {
    return setRegistrationId(paramContext, "");
  }

  private static int getAppVersion(Context paramContext)
  {
    try
    {
      int i = paramContext.getPackageManager().getPackageInfo(paramContext.getPackageName(), 0).versionCode;
      return i;
    }
    catch (PackageManager.NameNotFoundException localNameNotFoundException)
    {
      throw new RuntimeException("Coult not get package name: " + localNameNotFoundException);
    }
  }

  static int getBackoff(Context paramContext)
  {
    return getGCMPreferences(paramContext).getInt("backoff_ms", 3000);
  }

  private static SharedPreferences getGCMPreferences(Context paramContext)
  {
    return paramContext.getSharedPreferences("com.google.android.gcm", 0);
  }

  public static String getRegistrationId(Context paramContext)
  {
    SharedPreferences localSharedPreferences = getGCMPreferences(paramContext);
    String str = localSharedPreferences.getString("regId", "");
    int i = localSharedPreferences.getInt("appVersion", -2147483648);
    int j = getAppVersion(paramContext);
    if ((i != -2147483648) && (i != j))
    {
      Log.v("GCMRegistrar", "App version changed from " + i + " to " + j + "; resetting registration id");
      clearRegistrationId(paramContext);
      str = "";
    }
    return str;
  }

  static void internalRegister(Context paramContext, String[] paramArrayOfString)
  {
    if ((paramArrayOfString == null) || (paramArrayOfString.length == 0))
      throw new IllegalArgumentException("No senderIds");
    StringBuilder localStringBuilder = new StringBuilder(paramArrayOfString[0]);
    for (int i = 1; ; i++)
    {
      if (i >= paramArrayOfString.length)
      {
        String str = localStringBuilder.toString();
        Log.v("GCMRegistrar", "Registering app " + paramContext.getPackageName() + " of senders " + str);
        Intent localIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
        localIntent.setPackage("com.google.android.gsf");
        localIntent.putExtra("app", PendingIntent.getBroadcast(paramContext, 0, new Intent(), 0));
        localIntent.putExtra("sender", str);
        paramContext.startService(localIntent);
        return;
      }
      localStringBuilder.append(',').append(paramArrayOfString[i]);
    }
  }

  static void internalUnregister(Context paramContext)
  {
    Log.v("GCMRegistrar", "Unregistering app " + paramContext.getPackageName());
    Intent localIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER");
    localIntent.setPackage("com.google.android.gsf");
    localIntent.putExtra("app", PendingIntent.getBroadcast(paramContext, 0, new Intent(), 0));
    paramContext.startService(localIntent);
  }

  public static boolean isRegistered(Context paramContext)
  {
    return getRegistrationId(paramContext).length() > 0;
  }

  public static boolean isRegisteredOnServer(Context paramContext)
  {
    boolean bool = getGCMPreferences(paramContext).getBoolean("onServer", false);
    Log.v("GCMRegistrar", "Is registered on server: " + bool);
    return bool;
  }

  public static void onDestroy(Context paramContext)
  {
    try
    {
      if (sRetryReceiver != null)
      {
        Log.v("GCMRegistrar", "Unregistering receiver");
        paramContext.unregisterReceiver(sRetryReceiver);
        sRetryReceiver = null;
      }
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public static void register(Context paramContext, String[] paramArrayOfString)
  {
    resetBackoff(paramContext);
    internalRegister(paramContext, paramArrayOfString);
  }

  static void resetBackoff(Context paramContext)
  {
    Log.d("GCMRegistrar", "resetting backoff for " + paramContext.getPackageName());
    setBackoff(paramContext, 3000);
  }

  static void setBackoff(Context paramContext, int paramInt)
  {
    SharedPreferences.Editor localEditor = getGCMPreferences(paramContext).edit();
    localEditor.putInt("backoff_ms", paramInt);
    localEditor.commit();
  }

  public static void setRegisteredOnServer(Context paramContext, boolean paramBoolean)
  {
    SharedPreferences localSharedPreferences = getGCMPreferences(paramContext);
    Log.v("GCMRegistrar", "Setting registered on server status as: " + paramBoolean);
    SharedPreferences.Editor localEditor = localSharedPreferences.edit();
    localEditor.putBoolean("onServer", paramBoolean);
    localEditor.commit();
  }

  static String setRegistrationId(Context paramContext, String paramString)
  {
    SharedPreferences localSharedPreferences = getGCMPreferences(paramContext);
    String str = localSharedPreferences.getString("regId", "");
    int i = getAppVersion(paramContext);
    Log.v("GCMRegistrar", "Saving regId on app version " + i);
    SharedPreferences.Editor localEditor = localSharedPreferences.edit();
    localEditor.putString("regId", paramString);
    localEditor.putInt("appVersion", i);
    localEditor.commit();
    return str;
  }

  private static void setRetryBroadcastReceiver(Context paramContext)
  {
    try
    {
      if (sRetryReceiver == null)
      {
        sRetryReceiver = new GCMBroadcastReceiver();
        String str1 = paramContext.getPackageName();
        IntentFilter localIntentFilter = new IntentFilter("com.google.android.gcm.intent.RETRY");
        localIntentFilter.addCategory(str1);
        String str2 = str1 + ".permission.C2D_MESSAGE";
        Log.v("GCMRegistrar", "Registering receiver");
        paramContext.registerReceiver(sRetryReceiver, localIntentFilter, str2, null);
      }
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public static void unregister(Context paramContext)
  {
    resetBackoff(paramContext);
    internalUnregister(paramContext);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.google.android.gcm.GCMRegistrar
 * JD-Core Version:    0.6.2
 */